package com.example.ruralservicedigitalplatform.service.impl;

import com.example.ruralservicedigitalplatform.domain.po.Admin;
import com.example.ruralservicedigitalplatform.domain.query.PageBean;
import com.example.ruralservicedigitalplatform.mapper.AdminMapper;
import com.example.ruralservicedigitalplatform.service.AdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(Admin account) {
        Admin account1 = adminMapper.getByUsernameAndPassword(account);
        return account1;
    }
    @Override//分页查询管理员
    public PageBean page(Integer page, Integer pageSize, String adminName,Integer gender,String phoneNumber,Integer age,String image,String idNumber,LocalDate begin, LocalDate end) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
        //2.执行查询
        List<Admin> accountList = adminMapper.list(adminName,gender,phoneNumber,age,image,idNumber,begin,end);
        Page<Admin> p = (Page<Admin>)accountList;
        //3.封装PageBean对象
        return new PageBean(p.getTotal(),p.getResult());
    }

    @Override//更改管理员信息
    public void update(Admin admin) {
        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.update(admin);
    }

    @Override//新增管理员
    public void add(Admin admin) {
        admin.setCreateTime(LocalDateTime.now());
        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.insert(admin);
    }

    @Override//删除管理员
    public void delete(List<Integer> ids) {
        adminMapper.delete(ids);
    }
}
